package cn.howxu.yichen_ovo.datagen;

import cn.howxu.yichen_ovo.YiChenOVO;
import cn.howxu.yichen_ovo.registry.DollRegistryEvent;
import cn.howxu.yichen_ovo.init.ModBlocks;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.ForgeRegistries;

public class BlockStateGenerator extends BlockStateProvider {
    public BlockStateGenerator(PackOutput output, ExistingFileHelper exFileHelper) {
        super(output, YiChenOVO.MODID, exFileHelper);
    }

    @Override
    protected void registerStatesAndModels() {
        
        DollRegistryEvent.BLOCKS.values().forEach(block -> {
            registerSpecialBlock(block,"block/doll/");
        });
        
        ModBlocks.BLOCKS.forEach(blockRegistryObject -> {
            registerBlockModelAndItem(blockRegistryObject.get());
        });
        
        registerSpecialBlock(ModBlocks.ALBOOK.get());
        registerSpecialBlock(ModBlocks.WINE.get());
    }

    public void registerBlockModelAndItem(Block block){
        this.simpleBlockWithItem(block,this.cubeAll(block));
    }

    public void registerSpecialBlock(Block block){
        var key = ForgeRegistries.BLOCKS.getKey(block);
        if (key == null) {
            return;
        }
        var location = modLoc("block/" + key.getPath());
        horizontalBlock(block, models().getExistingFile(location));
    }

    public void registerSpecialBlock(Block block,String specialLoc){
        var key = ForgeRegistries.BLOCKS.getKey(block);
        if (key == null) {
            return;
        }
        var location = modLoc(specialLoc + key.getPath());
        horizontalBlock(block, models().getExistingFile(location));
    }
}
